<?php
/**
 * 用户组
 * @author zlj <389843954@qq.com>
 */

namespace app\manage\controller;
use think\Request;
use think\Model;
use app\common\model\Group as GroupModel;
use app\common\model\Menu;
use app\common\model\Permission;
class Group extends Common
{
	/**
	 * 用户组
	 * @return [type] [description]
	 */

	public function lists(){

		$groupModel = new GroupModel();
		$data = $groupModel->gList();
		return view('',['data'=>$data,'title'=>'用户组']);
	}

	/**
	 * 权限页面
	 * @return [type] [description]
	 */
	public function permiss(){

		if(request()->isGet()){
			$gid = input('id');

			//菜单列表
			$menuModel = new Menu();
			$permissModel = new Permission();
			$plist = $menuModel->node();

			$gper = $permissModel->gropuPre($gid);
			$mid = array();
			foreach ($gper as $value) {
				array_push($mid,$value->id);
			}

			$res = [
				'data'=>$plist,
				'gid'=>$gid,
				'mid'=>$mid,
				'title'=>'权限设置'
			];
			return view('',$res);
		}
	}

	/**
	 * 权限修改
	 */
	public function addPer(){
		if(request()->isPost()){
			$mid = input('post.mid/a');
			$gid = input('post.gid',0);

			$permissModel = new Permission();
			$groupModel = new GroupModel();

			$ginfo = $groupModel->gFind($gid);
			if(!$ginfo){
				$this->error('错误操作');
			}
			$ginfo = $ginfo->getData();
			if($ginfo['is_sys']!=0){
				//只可设置管理员组权限
				$this->error('错误操作');
			}
			//修改操作
			$res = $permissModel->addPer($gid,$mid);
			if($res){
				$this->success('提交成功',url('manage/Group/permiss',array('id'=>$gid)));
			}else{
				$this->error('错误操作');
			}
		}
	}
}